package com.berrontech.asbog;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Create by levent8421 2021/4/16 14:10
 * BootReceiver
 * 启动监听
 *
 * @author levent8421
 */
public class BootReceiver extends BroadcastReceiver {
    public static final String TAG = "BootReceiver";
    private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.w(TAG, "onReceive: Receiver Enter");
        if (ACTION_BOOT.equals(action)) {
            Log.w(TAG, "Starting activity");
            final Intent activityIntent = new Intent(context, MainActivity.class);
            activityIntent.putExtra(MainActivity.AUTO_START, true);
            activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                context.startActivity(activityIntent);
                Log.w(TAG, "Starting activity Success");
            } catch (Exception e) {
                Log.e(TAG, "onReceive: Error On Start activity", e);
            }
        }
    }
}
